package com.ljx.recruitment.user.typehandler;

import cn.hutool.json.JSONUtil;
import com.ljx.recruitment.interview.domain.dto.ResumeItmDto;
import com.ljx.recruitment.user.typehandler.details.ResumeDetails;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedTypes;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * @Author: LiJunXi
 * @Description:
 * @Date: 2024-11-02  21:29
 */
@MappedTypes(ResumeDetails.class)
public class TenantResumeTypeHandler extends BaseTypeHandler<ResumeDetails> {

    @Override
    public void setNonNullParameter(PreparedStatement preparedStatement, int i, ResumeDetails themes, JdbcType jdbcType) throws SQLException {
        preparedStatement.setString(i, JSONUtil.toJsonStr(themes));
    }

    @Override
    public ResumeDetails getNullableResult(ResultSet resultSet, String s) throws SQLException {
        List<ResumeItmDto> list = JSONUtil.toList(resultSet.getString(s), ResumeItmDto.class);
        return new ResumeDetails(list);
    }

    @Override
    public ResumeDetails getNullableResult(ResultSet resultSet, int i) throws SQLException {
        List<ResumeItmDto> list = JSONUtil.toList(resultSet.getString(i), ResumeItmDto.class);
        return new ResumeDetails(list);
    }

    @Override
    public ResumeDetails getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
        List<ResumeItmDto> list = JSONUtil.toList(callableStatement.getString(i), ResumeItmDto.class);
        return new ResumeDetails(list);
    }
}